package com.example.shop.controller;

import com.example.shop.entity.Products;
import com.example.shop.service.ProductsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName ProductsController
 * @Description TODO
 * @Author 萍
 * @Date 2025/3/26 10:24
 */
@RestController
@RequestMapping("/products")
public class ProductsController {

    @Autowired
    private ProductsService productsService;

    /**
     * 通过ID查询单条数据
     *
     * @param productsid 主键
     * @return 实例对象
     */
    @GetMapping("/{productsid}")
    public Products queryById(@PathVariable("productsid") Integer productsid) {
        return productsService.queryById(productsid);
    }

    /**
     * 新增数据
     *
     * @param products 实例对象
     * @return 实例对象
     */
    @PostMapping
    public Products insert(@RequestBody Products products) {
        return productsService.insert(products);
    }

    /**
     * 修改数据
     *
     * @param products 实例对象
     * @return 实例对象
     */
    @PutMapping
    public Products update(@RequestBody Products products) {
        return productsService.update(products);
    }

    /**
     * 通过主键删除数据
     *
     * @param productsid 主键
     * @return 是否成功
     */
    @DeleteMapping("/{productsid}")
    public boolean deleteById(@PathVariable("productsid") Integer productsid) {
        return productsService.deleteById(productsid);
    }
}
